﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}@using LeSoft.Application.Code;
<script>
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    var keyValue = request('keyValue');
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //性质
        $("#Nature").ComboBox({
            data: [{ "key": "1", "value": "单元表" }, { "key": "3", "value": "虚拟表" }],
            id: "key",
            text: "value",
            description: "==请选择==",
        });
        $("#Type").ComboBoxTree({
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson?Encode=EnergyMeterType",
            description: "==请选表类型==",
            height: "250px"
        });
      
        var obj = new Object();        
        obj.EnergyMeterId = keyValue;       
        $("#EnergyFeeItem").treeview({
            url: "/FinancialManage/FeeItems/GetItemsTreeList",
            param: { "queryJson": JSON.stringify(obj) },
            height: 120,
            showcheck: true,           
        });

     
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../ResourceManage/RS_EnergyMeter/GetInfoFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    $('input[name="MeterType"][value=' + data.MeterType + ']').attr("checked", true);
                }
            });
        }
    }

 
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["MeterType"] = $('input[name="MeterType"]:checked ').val()
        var selectedItemData = $("#EnergyFeeItem").getCheckedAllNodes();
        var FeeItemListStr = selectedItemData.join(',');      
        $.SaveForm({
            url: "../../ResourceManage/RS_EnergyMeter/SaveForm" ,
            param: { "keyValue": keyValue, "EnergyMeter": JSON.stringify(postData), "FeeItemListStr": FeeItemListStr },
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        });
    }
</script>
<div style="margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr>
            <td class="formTitle"></td>
            <td class="formValue"></td>            
            <td class="formTitle"></td>
            <td class="formValue"></td>
        </tr>
        <tr>
            <td class="formTitle">表名称<font face="宋体">*</font></td>
            <td class="formValue" colspan="3">
                <input id="Name" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">表性质<font face="宋体">*</font></td>
            <td class="formValue">
                <div id="Nature" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
            </td>
            <td class="formTitle">表种类<font face="宋体">*</font></td>
            <td class="formValue">
                <div id="Type" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">表容量</td>
            <td class="formValue">
                <input id="Volume" type="number" class="form-control" />
            </td>
            <td class="formTitle">走表类型</td>
            <td class="formValue">
                <input name="MeterType" type="radio" value="1" />正转
                <input name="MeterType" type="radio" value="0" />反转
            </td>
        </tr>
        <tr>
            <td class="formTitle">倍率</td>
            <td class="formValue">
                <input id="Rate" type="number" class="form-control" />
            </td>
            <td class="formTitle">量程</td>
            <td class="formValue">
                <input id="Range" type="number" class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">每月最低用量</td>
            <td class="formValue">
                <input id="MinVolume" type="number" class="form-control" />
            </td>
            <td class="formTitle">每月最高用量</td>
            <td class="formValue">
                <input id="MaxVolume" type="number" class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">对应能耗费项</td>
            <td class="formValue" colspan="3">
                <div id="EnergyFeeItem" isvalid="yes" checkexpession="IsScript" style="border: 1px solid #c5c1c1;"></div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">备注</td>
            <td class="formValue" colspan="3">
                <textarea id="Description" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
    </table>

</div>
